﻿/**
 * @author sminutoli
 * version 1.0
 * Convierte una collection de key/values en tags de XML
 */
import com.dinmax.flash.utilities.xml.XMLCapable;
import com.dinmax.flash.common.collection.Collection;

class com.dinmax.flash.utilities.xml.XMLParameters
extends Collection
implements XMLCapable {
	
	private var nodeName:String = "parameters";
	private var childName:String = "parameter";
	private var keyName:String = "name";
	private var valueName:String = "value";
	
		
	public function getValueName():String {
		return valueName;
	}

	public function setValueName(valueName:String):Void {
		this.valueName = valueName;
	}

	public function getNodeName():String {
		return nodeName;
	}

	public function setNodeName(nodeName:String):Void {
		this.nodeName = nodeName;
	}

	public function getKeyName():String {
		return keyName;
	}

	public function setKeyName(keyName:String):Void {
		this.keyName = keyName;
	}
	public function getChildName():String {
		return childName;
	}

	public function setChildName(childName:String):Void {
		this.childName = childName;
	}
	
	function toXML(noHeader:Boolean):String {
		var nLength:Number = super.getItems().length;
		var xmlPar:String = new String();
		if(!noHeader) xmlPar+="<"+this.getNodeName()+"> ";
		for(var i:Number=0; i < nLength; i++){
			xmlPar+="<"+this.getChildName()+" ";
			xmlPar+=this.getKeyName()+"=";
			xmlPar+="'"+super.getItems()[i].getKey()+"' ";
			xmlPar+=this.getValueName()+"=";
			xmlPar+="'"+super.getItems()[i].getValue()+"' ";
			xmlPar+="/>";
		};
		if(!noHeader)xmlPar+="</"+this.getNodeName()+">";
		
		return xmlPar;
	};

}